home *** CD-ROM | disk | FTP | other *** search
- {
- OVRACT is a unit that captures data about the activities of the overlay
- manager in a Turbo Pascal 5.x program and saves it in a disk file.
-
- To use it, add the unit OVRACT as near as possible to the beginning of the uses
- statement of your main program. Compile and run the program normally. If
- you are running DOS 3.0 or later, a file named ProgName.OVD will be produced,
- where ProgName is the root name of your EXE file. Under earlier versions of
- DOS, a file named OVRACT.OVD is produced.
-
- Written by Ron Schuster (CIS 76666,2322). Copyright (c) 1989.
- All rights reserved. May be distributed freely, but not for a profit.
-
- This program was originally based on the overlay profiler OVRPROF
- written by Richard Casey (CIS 72247,151).
-
- Portions of this program originally appeared in OVRSIZ by Kim Kokkonen,
- TurboPower Software (CIS 76004,2611), and were used with the permission of
- the author. Copyright (c) 1989, TurboPower Software. All rights reserved.
- May be distributed freely, but not for a profit.
-
-
- Version 1.0, 11/21/89
- --------------------
- Initial release.
- }
-
- {$R-,S-,I-,V-,F-,B-,O-}
-
-
- unit OvrAct;
-
- interface
-
- implementation
-
- uses
- Dos, Overlay;
-
- type
- DispatcherHeader = record
- ReturnInt : Word;
- ReturnOfs : Word;
- FileOfs : LongInt;
- CodeSize : Word;
- FixupSize : Word;
- EntryPts : Word;
- CodeListNext : Word;
- LoadSegment : Word;
- Reprieved : Word;
- LoadListNext : Word;
- end;
-
- ProcType = procedure;
-
- Words = record
- Lo,Hi:Word;
- end;
-
- var
- OvrDataFile : file of Word;
- SaveExitProc : pointer;
- StartTime : LongInt;
- Ticks : LongInt absolute $40:$6C;
- OldOvrHeapOrg,
- OldOvrHeapEnd : Word;
- SaveDebugPtr : pointer;
- OvrDataFileName : PathStr;
-
- const
- EndListMark : Word = 0;
- OvrHeapMark : Word = $FFFF;
- FileFormatVersion : Word = 1;
-
- procedure WriteCodeList;
- var
- P : Word;
- begin
- P := OvrCodeList;
- while P <> 0 do begin
- Write (OvrDataFile,P);
- with DispatcherHeader(Ptr(P + PrefixSeg + $10, 0)^) do begin
- Write (OvrDataFile, Words(FileOfs).Lo, Words(FileOfs).Hi,
- CodeSize, FixupSize, EntryPts);
- P := CodeListNext;
- end;
- end;
- Write (OvrDataFile, EndListMark);
- end;
-
- {$F+}
- procedure OvrDebug;
- var
- Time : LongInt;
- P : Word;
- OvrSeg, OvrOfs: word;
- begin
- Inline( $8C/$86/OvrSeg { mov OvrSeg, es }
- /$89/$9E/OvrOfs ); { mov OvrOfs, bx }
-
- if SaveDebugPtr <> nil then
- ProcType(SaveDebugPtr); { Let the debugger do its thing first }
-
- if FileRec(OvrDataFile).Mode = fmClosed then
- { an overlaid unit's exit procedure must have happened after ours }
- Exit;
-
- Time := Ticks - StartTime;
- Write (OvrDataFile, Words(Time).Lo, Words(Time).Hi);
-
- if (OvrHeapOrg <> OldOvrHeapOrg) or (OvrHeapEnd <> OldOvrHeapEnd) then begin
- { overlay buffer has changed, write new limits }
- Write (OvrDataFile, OvrHeapMark, OvrHeapOrg, OvrHeapEnd);
- OldOvrHeapOrg := OvrHeapOrg;
- OldOvrHeapEnd := OvrHeapEnd;
- end;
-
- Write (OvrDataFile, OvrSeg, OvrOfs);
-
- if DispatcherHeader(Ptr(OvrSeg,0)^).Reprieved = 0 then begin
- { not a reprieve event, write load list }
- P := OvrLoadList;
- while P <> 0 do begin
- Write (OvrDataFile, P, DispatcherHeader(Ptr(P,0)^).LoadSegment);
- P := DispatcherHeader(Ptr(P,0)^).LoadListNext;
- end;
- end;
- Write (OvrDataFile, EndListMark);
- end;
-
- procedure OvrProfExit;
- begin
- ExitProc := SaveExitProc;
- Close (OvrDataFile);
- end;
- {$F-}
-
- function HasExtension(Name : String; var DotPos : Word) : Boolean;
- {-Return whether and position of extension separator dot in a pathname}
- var
- I : Word;
- begin
- DotPos := 0;
- for I := Length(Name) downto 1 do
- if (Name[I] = '.') and (DotPos = 0) then
- DotPos := I;
- HasExtension := (DotPos > 0) and (Pos('\', Copy(Name, Succ(DotPos), 64)) = 0);
- end;
-
- function ForceExtension(Name, Ext : String) : String;
- {-Return a pathname with the specified extension attached}
- var
- DotPos : Word;
- begin
- if HasExtension(Name, DotPos) then
- ForceExtension := Copy(Name, 1, DotPos)+Ext
- else
- ForceExtension := Name+'.'+Ext;
- end;
-
-
- begin
- OldOvrHeapOrg := 0;
- OldOvrHeapEnd := 0;
- StartTime := Ticks;
- if Lo(Dos.DosVersion) < 3 then
- OvrDataFileName := 'OvrAct.OVD'
- else
- OvrDataFileName := ForceExtension(ParamStr(0), 'OVD');
-
- assign (OvrDataFile, OvrDataFileName);
- {$I-}
- rewrite (OvrDataFile);
- {$I+}
- if IOResult <> 0 then begin
- Writeln ('Could not open ', OvrDataFileName,' for output');
- Halt(1);
- end;
- SaveExitProc := ExitProc;
- ExitProc := @OvrProfExit;
- SaveDebugPtr := OvrDebugPtr;
- OvrDebugPtr := @OvrDebug;
- Write (OvrDataFile, FileFormatVersion, PrefixSeg);
- WriteCodeList;
- end.
-